<template>
  <div class="search ct">
    <div class="detail-content">
      <div class="c-l">
        <div class="l1">站内搜索</div>
        <div class="l2">
          <el-input
            v-model="input2"
            style="width: 240px"
            size="large"
            :prefix-icon="Search"
            placeholder="请输入关键词"
				  />
          <!-- <el-input
            v-model="input2"
            style="width: 240px"
            size="large"
            :prefix-icon="Search"
            readonly
            placeholder="全站搜索"
				  /> -->
          <el-button @click="search1" type="primary">搜索</el-button>

        </div>
      </div>
      <div class="c-r">
        <el-breadcrumb class="head-nav" :separator-icon="ArrowRight">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>站内搜索</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="ret" v-if="input1 && works.list.length">
          已为您找到
          <div class="sp">{{ input1 }}</div>
          相关的文章
        </div>
        <div v-else style="padding-top: 20px;"></div>
        <div class="item-content">
        <div class="new-info">
          <div class="info-item" @click="goDetail(item)" v-for="item in works.list">
            <div class="info-i-t">
              <div class="i-l">{{ item.title }}</div>
              <div class="i-r">
                {{ item.createdTime }}
              </div>
            </div>
          </div>
        </div>
        <div class="item-page">
          <el-pagination
          :current-page="works.page"
            :page-size="15"
            background
            layout="prev, pager, next, jumper"
            prev-text="上一页"
            next-text="下一页"
            :total="works.total"
            @current-change="getPageInformation"
          />
        </div>
      </div>

      </div>
    </div>
  </div>
</template>  
<script setup>
import { ArrowRight } from '@element-plus/icons-vue'
import { pageIntegratedQuery } from '@/api/home';
import { useRouter } from 'vue-router';

import { computed, reactive, ref } from 'vue'
const router = useRouter();
const input2 = ref('');
const input1 = ref('');

const search1 = () => {
  input1.value = input2.value;
  works.title = input2.value;
  getPageInformation(0);
}

const works = reactive({
    list: [],
    total: 0,
    page: 1,
    title: ''
  });

  const getPageInformation = async(pageNum=1) => {
    const params = {
      params: {
        status: true,
        // courtyardId: id.value,
        title: works.title
      },
      page: {
        pageSize: 15,
        pageNum,
      }
    }
    const ret = await pageIntegratedQuery(params)
    works.list = ret?.data?.list || [];
    works.total = ret?.data?.total;
    works.page = pageNum;
  }

  getPageInformation();

// pageIntegratedQuery
const goDetail = (item) => {
  const map1 = {
    information: 'yardlog',
    research: 'science',
    work: 'job',
    policies: 'policy',
    bulletin: 'bulletin'
  }
  let key = map1[item.type]
  if(!key) return
  router.push(`/job/jobdetail/${item.id}?type=${key}`)
}
</script>
<style lang="scss" scoped>
.search {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  color: #777;
  padding: 0 10%;
  .detail-content {
    display: flex;
    margin-bottom: 40px;
    flex: 1;
    padding-top: 30px;
    .c-l {
      background-color: #4aa97d;
      width: 300px;
      margin-right: 20px;
     .l1 {
      height: 110px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 35px;
      // font-weight: bold;
      color: #fff;
     }
     .l2 {
      background-color: #ececec;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 20px 0;
      .el-input {
        width: 280px !important;
        margin-bottom: 20px;
        height: 50px;
        font-size: 16px;
      }
      .el-button {
        width: 280px !important;
        height: 50px;
        font-size: 16px;
      }
     }
    }
    .c-r {
      flex:1;
      .head-nav {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        font-size: 24px;
        width: 100%;
        height: 40px;
        border-bottom: 1px solid #333;
      }
      .ret {
        height: 50px;
        background-color: #fff;
        display: flex;
        font-size: 20px;
        align-items: center;
        padding: 0 20px;
        margin: 20px 0;
        box-shadow: 1px 1px 10px 1px #ccc;
        .sp {
          color: #4aa97d;
          font-weight: bold;
        }
      }
      .item-content {
        // padding-top: 25px;
        display: flex;
        flex-direction: column;
        .new-info {
          flex: 1;
          background-color: #fff;
          padding: 20px 40px;
          overflow: hidden;
          color: #777;
          .info-item {
            border-bottom: 2px solid #e5e5e5;
            cursor: pointer;
            &:last-child{
              border-bottom: 0 none;
            }
          }
          .info-i-t {
            font-size: 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 15px 0;
            .i-l {
              text-overflow: ellipsis;
              overflow: hidden;
              white-space: nowrap;
            }
            .i-r {
              margin-left: 40px;
            }
          }
        }
        .item-page {
          height: 100px;
          display: flex;
          align-items: center;
          justify-content: center;
          margin-top: 20px;
          :deep(.el-pagination) {
            button, li {
              background-color: transparent;
              width: 60px;
              height: 60px;
              border: 2px solid #e5e5e5;
              border-radius: 5px;
              color: #777;
              font-size: 18px;
              font-weight: normal;
              margin-right: 20px;
            }
            button {
              border: 0 none;
            }
            .el-pagination__jump {
              color: #777;
              font-size: 18px;
            }
            .el-pagination__editor {
              min-width: 60px;
              min-height: 60px;
              font-size: 18px;
            }
            .el-input__wrapper {
              padding: 0;
            }
            .el-input__inner {
              color: #777 !important;
            }
          }
        }
      }
    }
  }
}
</style>